// pages/stvideo/stvideo.js
Page({
  data: {
    videosAll: [],
    videoList: [],
    currentVideo: {},
    videoPlaying: false
  },
  onLoad: function (options) {
    this.setData({
      onling: getApp().globalData.onling
    })
    if (options.key) {
      this.get_videos(options.key)
      wx.setNavigationBarTitle({
        title: '短视频详情'
      })
    }
  },
  onShareAppMessage() {

  },
  //获取视频资源
  get_videos(videoKey) {
    var _this = this
    wx.cloud.callFunction({
      name: 'video-json',
      data: {
        action: 'getVideoInfo',
        videoKey: videoKey
      },
      success: function (res) {
        console.log(res)
        var videoAll = res.result
        const videoList = videoAll.map((video, index) => ({
          id: index + 1,
          url: video.full_path,
          old_name: video.old_name,
          objectFit: "contain"
        }))
        _this.setData({
          videosAll: res.result,
          videoList: videoList
        })
      },
      fail: console.error
    })
  },
  // 视频列表监听
  onPlay(e) {
    var videoId = e.detail.activeId
    var videoList = this.data.videoList
    var videoObj
    for (let i = 0; i < videoList.length; i++) {
      if (i == videoId - 1)
        videoObj = videoList[i]
    }
    this.setData({
      currentVideo: videoObj
    })
    console.log(e)
  },

  onPause(e) {
    //  console.log('pause', e.detail.activeId)
  },

  onEnded(e) {},

  onError(e) {},

  onWaiting(e) {},

  onTimeUpdate(e) {},

  onProgress(e) {},

  onLoadedMetaData(e) {
    console.log('LoadedMetaData', e)
  }
})